package work.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import work.entity.Bookware;
import work.repository.BookwareRepository;
import work.service.BookwareService;

import java.util.List;

@Service
public class BookwareServiceImpl implements BookwareService {

    @Autowired
    private BookwareRepository bookwareRepository;

    @Override
    public Bookware findById(String bookWareId) {
        return bookwareRepository.findById(bookWareId);
    }

    @Override
    public List<Bookware> findByName(String bookName) {
        return bookwareRepository.findByName(bookName);
    }

    @Override
    public List<Bookware> findByAuthor(String bookAuthor) {
        return bookwareRepository.findByAuthor(bookAuthor);
    }

    @Override
    public List<Bookware> findByPublisher(String bookPublisher) {
        return bookwareRepository.findByPublisher(bookPublisher);
    }

    @Override
    public List<Bookware> findByType(String bookType) {
        return bookwareRepository.findByType(bookType);
    }

    @Override
    public List<Bookware> findAll() {
        return bookwareRepository.findAll();
    }

    @Override
    public List<Bookware> findByBookware(Bookware bookware) {
        return bookwareRepository.findByBookware(bookware);
    }

    @Override
    public List<Bookware> findByBookware1(Bookware bookware) {
        // 连接模糊查询字符串
        bookware.setBookWareId("%" + bookware.getBookWareId() + "%");
        bookware.setBookName("%" + bookware.getBookName() + "%");
        bookware.setBookAuthor("%" + bookware.getBookAuthor() + "%");
        bookware.setBookPublisher("%" + bookware.getBookPublisher() + "%");
        bookware.setBookType("%" + bookware.getBookType() + "%");
        return bookwareRepository.findByBookware1(bookware);
    }

    @Override
    public int updateWare(Bookware bookware) {
        return bookwareRepository.updateWare(bookware);
    }

    @Override
    public List<Bookware> orderByGrade() {
        return bookwareRepository.orderByGrade();
    }

    @Override
    public List<Bookware> orderByGradeDesc() {
        return bookwareRepository.orderByGradeDesc();
    }

    @Override
    public List<Bookware> orderByGradeAsc() {
        return bookwareRepository.orderByGradeAsc();
    }

    @Override
    public int insertBookware(Bookware bookware) {
        return bookwareRepository.insertBookware(bookware);
    }

    @Override
    public String findIdByName(String bookName) {
        return bookwareRepository.findIdByName(bookName);
    }

    @Override
    public String findNameById(String id) {
        return bookwareRepository.findNameById(id);
    }
}
